package com.jrsoft.bim.web;

import com.jrsoft.bim.dto.R;
import com.jrsoft.bim.util.ConvertUtil;
import com.jrsoft.bim.util.ConvertV2Util;
import com.jrsoft.bim.vo.ParseVO;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;
import java.util.Vector;

/**
 * ${DESCRIPTION}
 *
 * @author Blueeyedboy
 * @create 2019-12-20 10:47 AM
 **/
@RestController
public class DataController {

	@PostMapping("/convert")
	public R hello(@RequestBody ParseVO params){
		String srcPath = params.getSrcPath();
		String desPath = params.getDesPath();
		ConvertUtil.convert(srcPath,desPath);
		return R.ok();
	}
	@PostMapping("/convertV2")
	public R helloV2(@RequestBody ParseVO params){
		String srcPath = params.getSrcPath();
		String desPath = params.getDesPath();
		ConvertV2Util.convert(srcPath,desPath);
		return R.ok();
	}
	@GetMapping("/bridges")
	public Map<String,Object> getBridgeData(int page,int limit){
		Map<String,Object> result = new HashMap<>();
		String countSql = "select count(*) from T_BRIDGE";
		String querySql = "select * from T_BRIDGE order by LEVEL_ ,ID_ limit "+(page-1)*limit+" ,"+limit;
		System.out.println("countSql======="+countSql);
		System.out.println("querySql======="+querySql);
		long count = ConvertV2Util.dbUtil.getCount(countSql);
		Vector<Map<String,Object>> data = ConvertV2Util.dbUtil.getData(querySql);
		result.put("code",0);
		result.put("count",count);
		result.put("data",data);
		return result;
	}
	@GetMapping("/bridges/columns")
	public Map<String,Object> getBridgeColumns(String id,int page,int limit){
		Map<String,Object> result = new HashMap<>();
		String countSql = "select count(*) from T_BRIDGE_COLUMN where CMP_ID_ = '"+id+"'";
		String querySql = "select * from T_BRIDGE_COLUMN where CMP_ID_ = '"+id+"' order by LEVEL_ ,ID_ limit "+(page-1)*limit+" ,"+limit;
		System.out.println("countSql======="+countSql);
		System.out.println("querySql======="+querySql);
		long count = ConvertV2Util.dbUtil.getCount(countSql);
		Vector<Map<String,Object>> data = ConvertV2Util.dbUtil.getData(querySql);
		result.put("code",0);
		result.put("count",count);
		result.put("data",data);
		return result;
	}

	@GetMapping("/walls")
	public Map<String,Object> getWallData(int page,int limit){
		Map<String,Object> result = new HashMap<>();
		String countSql = "select count(*) from T_WALL";
		String querySql = "select * from T_WALL order by  LEVEL_ ,ID_ limit "+(page-1)*limit+" ,"+limit;
		System.out.println("countSql======="+countSql);
		System.out.println("querySql======="+querySql);
		long count = ConvertV2Util.dbUtil.getCount(countSql);
		Vector<Map<String,Object>> data = ConvertV2Util.dbUtil.getData(querySql);
		result.put("code",0);
		result.put("count",count);
		result.put("data",data);
		return result;
	}

}
